<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动画实例</title>
    <style>
        .container {
            flex: 1;
            min-height: 0;
            width: 100%;
            height: 50vh;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            background-color: rgba(0, 0, 0, 0.8);
        }

        .slinky {
            position: relative;
            width: 8em;
            height: 14em;
            transform-origin: 100% 50%;
        }

        .slinky__ring {
            border-radius: 50%;
            box-shadow: 0 0 0 0.25em #255ff4 inset, 0 0 4.5em rgba(37, 95, 244, 0.3) inset,
                0 0 4.25em rgba(37, 95, 244, 0.3);
            position: absolute;
            left: 0;
            width: inherit;
            height: 4em;
            transform: translateY(0) rotateZ(0) rotateX(0) translateX(-0.75em);
            transform-origin: 100% 50%;
        }
        .slinky__ring:nth-child(1) {
            bottom: 0em;
        }
        .slinky__ring:nth-child(2) {
            bottom: 0.25em;
        }
        .slinky__ring:nth-child(3) {
            bottom: 0.5em;
        }
        .slinky__ring:nth-child(4) {
            bottom: 0.75em;
        }
        .slinky__ring:nth-child(5) {
            bottom: 1em;
        }
        .slinky__ring:nth-child(6) {
            bottom: 1.25em;
        }
        .slinky__ring:nth-child(7) {
            bottom: 1.5em;
        }
        .slinky__ring:nth-child(8) {
            bottom: 1.75em;
        }
        .slinky__ring:nth-child(9) {
            bottom: 2em;
        }
        .slinky__ring:nth-child(10) {
            bottom: 2.25em;
        }
        .slinky__ring:nth-child(11) {
            bottom: 2.5em;
        }
        .slinky__ring:nth-child(12) {
            bottom: 2.75em;
        }
        .slinky__ring:nth-child(13) {
            bottom: 3em;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="slinky">
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
            <div class="slinky__ring"></div>
        </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.4.1/gsap.min.js"></script>
    <script>
        gsap.config({
            units: { x: "em", y: "em" }
        });

        const camera = gsap.timeline({
            repeat: -1,
            yoyo: false
        });

        camera.to(".slinky", {
            x: -8,
            duration: 3,
            ease: "linear"
        });

        const rings = document.querySelectorAll(".slinky__ring");

        let ringsTl = gsap.timeline({
            repeat: -1,
            defaults: {
                // duration: 1,
                ease: "linear",
                rotationX: 180,
                rotationZ: 185,
                x: 1
            }
        });
        // for (let i=0;i < 13;i++) {
        //     const ring = rings[i];
        //     ringsTl.to(ring, { y: 3 - i * 0.5 }, `-=${i * 0.065 + 0.5}`);
        // }
        rings.forEach((ring, index) => {
            const delay = index * 0.065 + 0.5;
            const yVal = -3 + index * 0.5;
            ringsTl.to(ring, { y: yVal }, `-=${delay}`);
        });
    </script>
</body>
</html>